package com.yehuishou.service.impl;


import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yehuishou.dao.AssessmentValueDao;
import com.yehuishou.dao.BackOrderDao;
import com.yehuishou.pojo.AssessmentValue;
import com.yehuishou.pojo.BackOrder;
import com.yehuishou.pojo.ImageFile1;
import com.yehuishou.service.BackOrderService;
@Service
public class BackOrderServiceImpl implements BackOrderService {
	
	@Autowired
	private BackOrderDao orderDao;
	
	@Resource
	private AssessmentValueDao assessmentValueDao;

	@Override
	public PageInfo<BackOrder> sel(Integer pageNum, Integer pageSize,BackOrder backOrder) {
		PageHelper.startPage(pageNum, pageSize);
		List<BackOrder> list=orderDao.sel(backOrder);
		PageInfo<BackOrder> pageinfo=new PageInfo<BackOrder>(list);
		return pageinfo;
	}

	@Override
	public boolean delete(BackOrder backOrder) {
		
		
				int i=orderDao.delete(backOrder);
				if(i>0){
					return true;
				}else{
					return false;
				}
	}


	@Override
	public List<BackOrder> getBack(String oid) {
		List<BackOrder> list=orderDao.getBack(oid);
		for (int i = 0; i <list.size(); i++) {
			String img=list.get(i).getImg_url();
			String back_assess=list.get(i).getBack_assess();
			
			if(back_assess!=null && !back_assess.equals("")){
				//将详情里的内存颜色 通过 ;号 进行分割 存到 字符串中
				String[] back_assesses=back_assess.substring(1, back_assess.length()).split(";");
				StringBuffer stringBuffer=new StringBuffer();
				for (String string : back_assesses) {
					 Integer back_value=Integer.parseInt(string);
					 AssessmentValue string1= orderDao.getAssessmentValueByvalid(back_value);
					String vString= string1.getAssess_value();
					
					stringBuffer.append(vString+"/");
					
				}
			        StringBuffer backvalue=stringBuffer;
			        list.get(i).setBack_assess(backvalue.toString());
					
				
			}
			
			if(img!=null && !img.equals("")) {
				//将详情里的图片 通过 ;号 进行分割 存到 字符串中
				String[] imgs=img.substring(1, img.length()).split(";");
					//将获得到的图片 信息 转化为 Integer 类型  
					Integer imgid=Integer.parseInt(imgs[0]);
					//查询图片地址 使用图片类接收
					ImageFile1 imagefile=orderDao.selimg(imgid);
					//将图片地址放入到集合中
					list.get(i).setImg_url(imagefile.getFilePath());
				}
		}
		return list;
	}

	@Override
	public List<BackOrder> selectStatus() {
		return orderDao.selectStatus();
	}

	@Override
	public BackOrder selectOne(Integer oid) {
		
		return orderDao.selectOne(oid);
	}

	@Override
	public void insertStore(BackOrder backOrder) {
		orderDao.insertStore(backOrder);
		
	}



	@Override
	public boolean checkStore(String store) {
		List<String> s= orderDao.checkStore(store);
		if(s.contains(store)){
			return true;
		}else{
			return false;
		}
		
	}

	@Override
	public PageInfo<BackOrder> sel1(Integer pageNum, Integer pageSize, BackOrder backOrder) {
		PageHelper.startPage(pageNum, pageSize);
		List<BackOrder> list=orderDao.sel1(backOrder);
		PageInfo<BackOrder> pageinfo=new PageInfo<BackOrder>(list);
		return pageinfo;
	}

	@Override
	public PageInfo<BackOrder> sel2(Integer pageNum, Integer pageSize, BackOrder backOrder) {
		PageHelper.startPage(pageNum, pageSize);
		List<BackOrder> list=orderDao.sel2(backOrder);
		PageInfo<BackOrder> pageinfo=new PageInfo<BackOrder>(list);
		return pageinfo;
	}

	

	@Override
	public void updatePrice(BackOrder backOrder) {
		orderDao.updatePrice(backOrder);
		
	}

	@Override
	public boolean deleteBack_order(BackOrder backOrder) {
		int i=orderDao.deleteBack_order(backOrder);
		if(i>0){
			return true;
		}else {
			return false;
		}
		
		
		
		
		
	}

	@Override
	public boolean updateStatus(BackOrder backOrder) {
		int s=orderDao.updateStatus(backOrder);
		if(s>0){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public PageInfo<BackOrder> selectStore(Integer pageNum, Integer pageSize, BackOrder backOrder) {
		
		PageHelper.startPage(pageNum, pageSize);
		List<BackOrder> list=orderDao.selectStore();
		PageInfo<BackOrder> pageinfo=new PageInfo<BackOrder>(list);
		return pageinfo;
	}

	@Override
	public PageInfo<BackOrder> sel3(Integer pageNum, Integer pageSize, BackOrder backOrder) {
		PageHelper.startPage(pageNum, pageSize);
		List<BackOrder> list=orderDao.sel3(backOrder);
		PageInfo<BackOrder> pageinfo=new PageInfo<BackOrder>(list);
		return pageinfo;
	}

	@Override
	public void deletezhongjianbiao(String[] oids) {
		orderDao.deletezhongjianbiao(oids);
		
	}

	@Override
	public void deletehuishoudingdan(String[] oids) {
		orderDao.deletehuishoudingdan(oids);
		
	}

	

	

	




	

	

	

	

	

	

	
	

}
